
package msu.ml.data.level2;

import java.io.*;

/**
 * @author Reginald M Mead
 * @version 1.0
 *
 * The Packet class represents a packet
 * of Nexrad Level II data.
 *
 */
public class VolumeDataBlock 
{
   public VolumeDataBlock(Level2InputStream stream)
   {
      name = new char[3];

      if(stream != null)
      {
         try
         {
            type = (char)stream.readByte();
            stream.readBytes(name, 0, 3);
            size = stream.readShort();
            majorVersion = stream.readByte();
            minorVersion = stream.readByte();
            latitude = stream.readFloat();
            longitude = stream.readFloat();
            siteHeight = stream.readShort();
            feedhornHeight = stream.readShort();
            calibration = stream.readFloat();
            hTx = stream.readFloat();
            vTx = stream.readFloat();
            zdrCalibration = stream.readFloat();
            initialDp = stream.readFloat();
            vcp = stream.readShort();
            stream.skip(2);
         }
         catch(IOException e)
         {
            System.out.println("VolumeDataBlock Error: " + e.getMessage());
            e.printStackTrace();
         }
      }
   }

   private static String formatString = "\nName: %1$c%2$s\nSize: %3$d\nMajor Version: %4$d\nMinor Version: %5$d\nLatitude: %6$f\nLongitude: %7$f\nSite Height: %8$d\nFeed Horn Height: %9$d\nCalibration: %10$f\nHorizontal Tx: %11$f\nVertical Tx: %12$f\nZDR Calibration: %13$f\nInitial DP: %14$f\nVCP: %15$d";

   public String toString()
   {
      return String.format(VolumeDataBlock.formatString, type, new String(name), size,
         majorVersion, minorVersion, latitude, longitude, siteHeight,
         feedhornHeight, calibration, hTx, vTx, zdrCalibration,
         initialDp, vcp); 
   }

   public char type;
   public char [] name;
   public short size;
   public byte majorVersion;
   public byte minorVersion;
   public float latitude;
   public float longitude;
   public short siteHeight;
   public short feedhornHeight;
   public float calibration;
   public float hTx;
   public float vTx;
   public float zdrCalibration;
   public float initialDp;
   public short vcp;
}
